﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace SharePoint.Contrib.Extensions
{
    /// <summary>
    /// Extension methods for the XmlNode class
    /// </summary>
    public static class XmlNodeExtensions
    {
        /// <summary>
        /// Converts the <see cref="T:System.Xml.XmlNode"/> to an instance of <see cref="T:System.Xml.Linq.XElement"/>.
        /// </summary>
        public static XElement ToXElement(this XmlNode instance)
        {
            XDocument xDoc = new XDocument();

            using (XmlWriter xmlWriter = xDoc.CreateWriter())
            {
                instance.WriteTo(xmlWriter);
            }

            return xDoc.Root;

        }


    }
}
